Skip to content

Conversation

phadej
Copy link
Collaborator

@phadej phadej commented Jul 13, 2017

An applicative ObjectParser letting us make "strict" object parsers. cc @hvr

Performance is slightly degraded, as you can suspect:

screenshot from 2017-07-13 16-22-16

OTOH in case of missing / extra keys parser will fail early.


Motivation: for the TokenStream parser #560 such interface would be needed. The objectField could be a member of new class:

BTW, why parseJSON :: Value -> Parser a and not parseJSON :: Parser a, where

 newtype Parser a = Parser {
       runParser :: forall f r.
                    JSONPath
+                -> Value
                 -> Failure f r
                 -> Success a f r
                 -> f r
     }

(Probably because of manual instances, i.e. not using combinators like withObject)

-- | "dual" of 'KeyValue'
class OP p op | p -> op | op -> p where
    objectField :: Text -> p a -> op a
    runObjectParser :: String -> op a -> p a

instance OP Parser ObjectParaser where
    ... 

EDIT: if aeson is a wrong place for this, I'll add it to aeson-extra.

TODO:

  • documentation
  • tests
  • generics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant